package com.example.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.sys.entity.User;
import com.example.sys.entity.UserRole;
import com.example.sys.mapper.UserRoleMapper;
import com.example.sys.service.IUserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.sys.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wuage
 * @since 2023-12-20
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements IUserRoleService {


    @Autowired
    private IUserService iUserService;
    @Override
    public List<User> listName() {
        QueryWrapper<UserRole> QueryWrapper = new QueryWrapper<>();
        QueryWrapper.eq("role_id", 2);

        List<UserRole> list = this.list(QueryWrapper);
        List<User> lists = new ArrayList<>();
        for (UserRole userRole:list){
            QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
            userQueryWrapper.eq("id", userRole.getUserId())
                    .select("id","username");

            User userLists = iUserService.getOne(userQueryWrapper);
            lists.add(userLists);
        }
        return lists;
    }
}
